# coding: utf-8
import traceback

from flask import render_template, redirect, request, url_for, flash, \
    current_app
from flask_login import login_user, login_required, logout_user

from common.log import log
from xshare.model.user import User
from xshare.forms.forms import LoginForm
from flask import Blueprint

user = Blueprint('user', __name__)


@user.route('/list/', methods=['GET'])
def user_list_page():
    try:
        page = request.args.get('page', 1, type=int)
        log.info(request.args)
        result = User.query.filter_by(is_deleted=0).order_by(
            User.create_time.desc())
        pagination = result.paginate(
            page, per_page=current_app.config['ADMIN_USER_PER_DEPART'],
            error_out=False)
        users = pagination.items

        return render_template('admin/user/list.html',
                               users=users, pagination=pagination,
                               endpoint='USER.user_list_page', page=page)
    except:
        log.info(traceback.format_exc())
        print(traceback.format_exc())
        return redirect(url_for("others.index"))
#
#
# @user.route('/logout')
# @login_required
# def logout():
#     logout_user()
#     flash(u'您已退出登陆。', 'success')
#     return redirect(url_for('.login'))
